package com.irdstudio.rsp.rule.api.rest;

import com.irdstudio.rsp.rule.common.BizUtil;
import com.irdstudio.rsp.rule.service.facade.SRuleParamService;
import com.irdstudio.rsp.rule.service.vo.SRuleParamVO;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.beans.web.controller.AbstractController;
import com.irdstudio.sdk.ssm.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class SRuleParamController extends AbstractController  {
	
	@Autowired
	@Qualifier("sRuleParamServiceImpl")
	private SRuleParamService sRuleParamService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/s/rule/params", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<SRuleParamVO>> querySRuleParamAll(
			SRuleParamVO vo) {		
		List<SRuleParamVO> outputVo = sRuleParamService.queryAllOwner(vo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/s/rule/param/{paramId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<SRuleParamVO> queryByPk(@PathVariable("paramId") String paramId) {		
		SRuleParamVO inVo = new SRuleParamVO();
				inVo.setParamId(new String(paramId));
		SRuleParamVO outputVo = sRuleParamService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param sRuleParam
	 * @return
	 */
	@RequestMapping(value="/s/rule/param", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody SRuleParamVO inSRuleParamVo) {
		try {
			int outputVo = sRuleParamService.deleteByPk(inSRuleParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
	
	/**
	 * 根据主键更新信息
	 * @param inSRuleParamVo
	 * @return
	 */
	@RequestMapping(value="/s/rule/param", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody SRuleParamVO inSRuleParamVo) {
		UserInfo userInfo = (UserInfo) this.httpRequest.getSession().getAttribute("userInfo");
		inSRuleParamVo.setUpdateTime(BizUtil.getCurrentTime());
		inSRuleParamVo.setUpdateUser(userInfo.getUserId());
		try {
			int outputVo = sRuleParamService.updateByPk(inSRuleParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
	
	/**
	 * 新增数据
	 * @param inSRuleParamVo
	 * @return
	 */
	@RequestMapping(value="/s/rule/param", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertSRuleParam(@RequestBody SRuleParamVO inSRuleParamVo) {
		UserInfo userInfo = (UserInfo) this.httpRequest.getSession().getAttribute("userInfo");
		inSRuleParamVo.setCreateTime(BizUtil.getCurrentTime());
		inSRuleParamVo.setCreateUser(userInfo.getUserId());
		inSRuleParamVo.setUpdateTime(BizUtil.getCurrentTime());
		inSRuleParamVo.setUpdateUser(userInfo.getUserId());
		try {
			int outputVo = sRuleParamService.insertSRuleParam(inSRuleParamVo);
			return getResponseData(outputVo);
		} catch (Exception e) {
			return getResponseData(-1);
		}

	}
}
